﻿
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>add</title>
    <link rel="stylesheet" href="~/Content/layui/css/layui.css" />
</head>
<body>
    <form class="layui-form" style="margin:20px;">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="Title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图Url</label>
            <div class="layui-input-block">
                <input type="text" name="CoverUrl" id="Cover" required lay-verify="required" placeholder="封面图" autocomplete="off" class="layui-input">
                <button type="button" class="layui-btn" id="test1">
                    <i class="layui-icon">&#xe67c;</i>上传封面图片
                </button>
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <input type="text" name="KeyWords" required lay-verify="required" placeholder="请输入关键词，逗号隔开" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件类型</label>
            <div class="layui-input-block">
                <select name="ClassTag" lay-verify="required">
                    <option value=""></option>
                    <option value=1>软件源码</option>
                    <option value=2>学习文件</option>
                    <option value=3>其他</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网盘地址</label>
            <div class="layui-input-block">
                <input type="text" name="WpUrl"  placeholder="网盘地址" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容介绍</label>
            <div class="layui-input-block">
                <textarea id="demo"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script type="text/javascript" src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['layedit', 'form','upload','jquery'],function () {
            var form = layui.form;
            var upload = layui.upload;
            var $ = layui.jquery;
            var layer = layui.layer, $ = layui.jquery, layedit = layui.layedit;
            form.on('submit(formDemo)', function (data) {
                data = $.extend(data.field, { HtmlContent: layedit.getContent(index) });
                delete data.file;
                console.log(JSON.stringify(data));
                $.post("/home/AddCode", { modelJson: JSON.stringify(data) }, function (res) {
                    if (res.code == 0) {
                        layer.msg("提交成功", { time: 1500, icon: 6 }, function () {
                            window.location.href = "/home/add";
                        });
                    } else {
                        layer.msg("提交失败", { time: 1500, icon: 5 });
                    }
                });
                return false;
            });
            layedit.set({
                uploadImage: {
                    url: '/home/upload' //接口url
                    , type: 'POST' //默认post
                }

            });
            var index=layedit.build('demo', {
                height: 400,
                tool: ['strong' //加粗
                    , 'italic' //斜体
                    , 'underline' //下划线
                    , 'del' //删除线
                    , '|' //分割线
                    , 'left' //左对齐
                    , 'center' //居中对齐
                    , 'right' //右对齐
                    , 'link' //超链接
                    , 'unlink' //清除链接
                    , 'face' //表情
                    , 'image' //插入图片
                    , 'help' //帮助
                ]
            });
            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                , url: '/home/upload/' //上传接口
                , done: function (res) {
                    $("#Cover").val(res.data.src);
                    layer.msg("上传成功");
                }
                , error: function () {
                    layer.msg("上传失败");
                }
            }); 
        });
    </script>

</body>

</html>
